/**
 * @class NG.controllers.WorkspaceList
 * @extends Ext.Controller
 * Workspace list controller. All list operations are handeled by this class.
 */
NG.controllers.WorkspaceList = Ext.extend(Ext.Controller, {
	
	/**
	 * Resets the workspace form and activates workspace form.
	 * @param {Object} options
	 */
    newWorkspace: function(options) {
    	app.views.workspaceForm.reset();
        app.views.viewport.setActiveItem(
            app.views.workspaceForm, options.animation
        );
    },

    /**
     * Activates first panel of the application's viewport. //TODO must activate the panel which activates workspace list panel. 
     * @param {Object} options
     */
	back: function(options) {
		app.views.viewport.setActiveItem(0);
	},

	/**
	 * Shows the workspace form with the selected workspace within list.<br>
	 * <b>options</b> params consists of<br>
	 * <li>id: Number. This is the unique id of the workspace which will be shown.
	 * @param {Object} options
	 */
	showWorkspace: function(options) {
		app.views.workspaceForm.setCaller(options.caller);
		Ext.dispatch({
			controller: app.controllers.workspaceForm,
			action: 'show',
			id: options.id
		});
	},
	
	/**
	 * Deletes the workspace with the selected workspace within list.<br>
	 * <b>options</b> params consists of<br>
	 * <li>id: Number. This is the unique id of the workspace which will be deleted.
	 * @param {Object} options
	 */
	deleteWorkspace: function(options) {
		var workspace = NG.stores.workspace.getById(options.id);
		Ext.Msg.confirm(workspace.getName(), MSG_DELETE_CONFIRM, doDelete);
		function doDelete(btn) {
			if (btn === "yes") {
				if (workspace) {
					NG.stores.workspace.removeWorkspaceById(options.id);
					NG.stores.workspace.sync();
				}
				else 
					Ext.Msg.alert('Uyarı', 'Proje bulunamadı!', Ext.emptyFn);				
			}
		}
	},

	/**
	 * Renders the map of workspace which id is gathered by <i>options.id</i>.<br>
	 * Workspace map is rendered on mapView.
	 * <b>options</b> params consists of<br>
	 * <li>id: Number. This is the unique id of the workspace which map will be rendered.
	 * @param {Object} options
	 */
	showMap: function(options) {
        NGLogger.info('show map with id: ' + options.id);	
        Ext.dispatch({
            controller: app.controllers.mapView
            ,action: 'renderWorkspace'
            ,id: options.id
        });        
	}
});

/**
 * 
 * @property app.controllers.workspaceList 
 */
app.controllers.workspaceList = new NG.controllers.WorkspaceList();